<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.util.*" %>
<%@ page import="oims.*, cims.*" %>
<%@ page import="order.*" %>
<% String contextPath = request.getContextPath(); %>
<%
	Order order = (Order)session.getAttribute("order");
	CustomerRecord crec = new CustomerRecord();
	Map<String,String> cmap = crec.getInfo(order.getCustomer());
	List<OrderRecordItem> items = (List<OrderRecordItem>)session.getAttribute("items");
	String msg = (String)request.getAttribute("msg");
	if (msg == null) msg = "";
	String[] numbers = new String[6];
	String[] prices = new String[6];
	String[] quantities = new String[6];
	for (int i=0 ; i<6 ; i++) {
		numbers[i] = request.getParameter("number" + i);
		prices[i] = request.getParameter("price" + i);
		quantities[i] = request.getParameter("quantity" + i);
	}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<link rel="stylesheet" href="<%= contextPath %>/css/style.css" type="text/css" />
		<title>注文管理システム</title>
	</head>
	<body>
		<div>
			<p><font color="red"><%= msg %></font></p>
			<table>
				<tr>
					<td width="80px">顧客番号</td>
					<td><%= order.getCustomer() %></td>
				</tr>
				<tr>
					<td>顧客名</td>
					<td><%= cmap.get("name") %></td>
				</tr>
				<tr>
					<td>住所</td>
					<td><%= cmap.get("address") %></td>
				</tr>
				<tr>
					<td>電話番号</td>
					<td><%=cmap.get("tel") %></td>
				</tr>
			</table>
		</div>
		<br />
		<form action="<%= contextPath %>/OrderEntryServlet">
			<input type="hidden" name="customer" value="<%= order.getCustomer() %>" />
			<table>
				<caption>注文内容</caption>
				<tr>
					<td width="20"></td>
					<td>商品番号</td>
					<td>単価</td>
					<td>数量</td>
					<td>在庫数</td>
				</tr>
				<% for (int i=0 ; i<6 ; i++) { %>
				<tr>
					<td><%= i+1 %></td>
					<% 	if (i < items.size()) { %>
					<%		OrderRecordItem item = items.get(i); %>
					<td><input type="text" name="number<%= i %>" size="4"  value="<%= item.getProduct() %>" /></td>
					<td><input type="text" name="price<%= i %>" size="4" value="<%= item.getPrice() %>" /></td>
					<td><input type="text" name="quantity<%= i %>" size="4" value="<%= item.getQuantity() %>" /></td>
					<td>
						<% if (item.getProduct() != null && item.getProduct().length() > 0) { %>
							<%= OrderItem.getStock(item.getProduct()) %>
						<% } %>
					</td>
					<% 	} else { %>
					<td>
						<input type="text" name="number<%= i %>" size="4"
					 	<% if (numbers[i] != null) { %>
					 		value="<%= numbers[i] %>"
					 	<% } %>
					 	/>
					 </td>
					<td>
						<input type="text" name="price<%= i %>" size="4"
					 	<% if (prices[i] != null) { %>
					 		value="<%= prices[i] %>"
					 	<% } %>
						 />
					</td>
					<td>
						<input type="text" name="quantity<%= i %>" size="4"
					 	<% if (quantities[i] != null) { %>
					 		value="<%= quantities[i] %>"
					 	<% } %>
						/>
					</td>
					<td>
					 	<% if (numbers[i] != null && numbers[i].length() > 0) { %>
							<%= OrderItem.getStock(numbers[i]) %>
					 	<% } %>
					</td>
					<% 	} %>
				</tr>
				<% } %>
			</table>
			<br />
			<table>
				<tr>
					<td>
						<a class="button" href="<%= contextPath %>/order/index.jsp">キャンセル</a>
					</td>
					<td>
						<input type="submit" value="送信" />
					</td>
				</tr>
			</table>
		</form>
	</body>
</html>